#!/usr/bin/env python
#coding=utf-8
import smtplib,time 
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText  
from config.config import to_email,mail_host,user_name,password,SMSNAME
           
# 发送邮件  
def send_mail(to_email):
    # 建立消息容器，正确的MIME类型是multipart/alternative
    msg=MIMEMultipart('alternative')
    msg['Subject'] = u'群呼系统通知!'
    msg['From'] = user_name
    msg['To'] = ";".join(to_email) 
    msg['date']=time.strftime('%a,%d %b %Y %H:%M:%S',time.localtime(time.time()))
    html = """\
    <html>
    <head>
    <style>
    p span{
    font:bold 12px arial;
    color:#ce4406;
    }
    p{
    color:#15c;
    }
    </style>
    </head>
    <body>    
    <p>短信账户: <strong>%s</strong> 余额不多了,请及时充值.&nbsp;&nbsp;&nbsp;&nbsp;<span>---群呼系统 </span></p>
    </body>
    </html>
    """% SMSNAME      
    part = MIMEText(html, 'html','utf-8')
    msg.attach(part)
    try:  
        server = smtplib.SMTP()  
        server.connect(mail_host,25)  
        server.login(user_name,password)  
        server.sendmail(user_name,to_email, msg.as_string())  
        server.close()  
        return True  
    except Exception, e:  
        print str(e)  
        return False  
if __name__ == '__main__': 
    #print 'main' 
    send_mail(to_email)
#     if send_mail(to_email,u"群呼系统通知!"):  
#         print "发送成功"  
#     else:  
#         print "发送失败"  